//
//  ZBMacros.h
//  ZBDay
//
//  Created by xzb on 2018/2/28.
//  Copyright © 2018年 xzb. All rights reserved.
//

#ifndef ZBMacros_h
#define ZBMacros_h

#ifdef DEBUG

#define Log(format, ...)        NSLog((@"💧💧💧%s [Line %d] 💧💧💧\n" format), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
#define tLog(format, ...)       NSLog((@"⭕️⭕️⭕️%s [Line %d] ⭕️⭕️⭕️\n" format), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
#define wLog(format, ...)       NSLog((@"❗️❗️❗️%s [Line %d] ❗️❗️❗️\n" format), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
#define eLog(format, ...)       NSLog((@"❌❌❌%s [Line %d] ❌❌❌\n" format), __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
#else
#define Log(format, ...)        ;
#define tLog(format, ...)       ;
#define wLog(format, ...)       ;
#define eLog(format, ...)       ;
#endif

#define kDebug                                   [ZBAppConfig isDebug]

#define kFontSize(fontSize)     [UIFont systemFontOfSize:fontSize]
#define kFontBoldSize(fontSize) [UIFont boldSystemFontOfSize:fontSize]

#define ZB_SINGLETON_INSTANCE_METHOD_DECLARATION +(instancetype)instance;

#define ZB_SINGLETON_INSTANCE_METHOD_IMPLEMENTATION \
    + (instancetype)instance                        \
    {                                               \
        static dispatch_once_t oncePredicate;       \
        static id instance;                         \
        dispatch_once(&oncePredicate, ^{            \
            instance = [[self alloc] init];           \
        });                                         \
        return instance;                            \
    }

#ifndef ZBLazyProperty
#define ZBLazyProperty(cls, var) \
    - (cls *)var                 \
    {                            \
        if (_ ## var == nil) {     \
            _ ## var = [cls new];  \
        }                        \
        return _ ## var;           \
    }
#endif

#ifndef ZBLazyPropertyWithInit
#define ZBLazyPropertyWithInit(cls, var, code) \
    - (cls *)var                               \
    {                                          \
        if (_ ## var == nil) {                   \
            _ ## var = [cls new];                \
            {                                  \
                code                           \
            }                                  \
        }                                      \
        return _ ## var;                         \
    }
#endif

//NSString的安全操作
#define STRING(str)                         ((str) != nil ? [NSString stringWithFormat:@"%@", (str)] : @"")

//安全调用block的方式
#define BLOCK_EXEC(block, ...) \
    if (block) {               \
        block(__VA_ARGS__);    \
    };

//设置时间格式
#define kTimeFormat(_timeInt_)              [[NSDate dateWithTimeIntervalSince1970:_timeInt_] stringWithFormat:@"MM-dd HH:mm"]

#define kAvailable_11(_newCode_, _oldCode_) if (@zb_available(iOS 11.0, *)) { \
        _newCode_ \
} else { \
        _oldCode_ \
}

#endif /* ZBMacros_h */
